<template>
	<view class="content">
		<headerbox :cixitype="cixi"></headerbox>
		<view class="pages">
			<view class="nav_top">
				<view :class="{on:isSelType==0}" @click="getSelType('0')">充值</view>
				<view :class="{on:isSelType==1}" @click="getSelType('1')">提款</view>
			</view>
			<view class="card" v-if="isSelType==0">
				<view id="nav_content_list">
					<view class="nav_content_list title">
						<!-- <view class="view4">充值方式</view> -->
						<view class="view1">金额</view>
						<view class="view2">状态</view>
						<view class="view3">时间</view>
					</view>
					<view class="nav_content_list" v-for="item in datas">
						<!-- <view class="view4">{{item.account}}</view> -->
						<view class="view1">{{item.money}}</view>
						<view :class="['view2',{'tongguo':item.status == 2},{'weitongguo':item.status == 3}]">
							{{status_fun(item.status)}}
						</view>
						<view class="view3">{{item.created_at}}</view>
					</view>
				</view>
			</view>
			<view class="card" v-if="isSelType==1">
				<view id="nav_content_list">
					<view class="nav_content_list title">
						<view class="view4">提款地址</view>
						<view class="view1">金额</view>
						<view class="view2">状态</view>
						<view class="view3">时间</view>
					</view>
					<view class="nav_content_list" v-for="item in datas">
						<view class="view4">{{item.bank_name}}</view>
						<view class="view1">{{item.money}}</view>
						<view :class="['view2',{'tongguo':item.status == 2},{'weitongguo':item.status == 3}]">
							{{status_fun(item.status)}}
						</view>
						<view class="view3">{{item.created_at}}</view>
					</view>
				</view>
			</view>

		</view>
		<view class="footer-bar" :class="cixi ? '':'footer-bar-detached'">
			<view class="fbitem" @click="goSwichPage('/pages/index/index')">
				<view class="image">
					<image src="../../static/timg/shouye.png" mode=""></image>
				</view>
				<view class="text">首页</view>
			</view>
			<view class="fbitem" @click="goSwichPage('/pages/contract/contract')">
				<view class="image">
					<image src="../../static/timg/heyue.png" mode=""></image>
				</view>
				<view class="text">合约</view>
			</view>
			<view class="fbitem" @click="goSwichPage('/pages/user/assets')">
				<view class="image">
					<image src="../../static/timg/zichan.png" mode=""></image>
				</view>
				<view class="text">资产</view>
			</view>
			<view class="fbitem" @click="goSwichPage('/pages/user/claim')">
				<view class="image">
					<image src="../../static/timg/suopei.png" mode=""></image>
				</view>
				<view class="text">索赔</view>
			</view>
		</view>
	</view>
</template>

<script>
	import headerbox from '@/pages/header.vue'
	import {
		recharge_record,
		drawing_record,
	} from '../../api/api.js'
	export default {
		components: {
			headerbox
		},
		data() {
			return {
				cixi: false,
				isrefresh: false,
				page: 1,
				datas: [],
				isSelType: 0
			}
		},
		onLoad(options) {
			this.page = 1
			if (options.isSelType) {
				this.isSelType = options.isSelType;
				if (this.isSelType == 0) {
					this.initData()
				} else if (this.isSelType == 1) {
					this.initDataTixian()
				}
			}
		},
		// 上拉加载更多
		onReachBottom() {
			console.log('触发我了吗---')
			this.page++; // 增加页码  
			if (this.isSelType == 0) {
				this.initData(); // 获取数据
			} else if (this.isSelType == 1) {
				this.initDataTixian(); // 获取数据
			}
		},
		onPageScroll(e) {
			if (e.scrollTop > 0) {
				this.cixi = true
			} else {
				this.cixi = false
			}
		},
		methods: {
			getSelType(num) {
				this.isSelType = num;
				this.page = 1;
				this.datas = []
				if (num == 0) {
					this.initData()
				} else if (num == 1) {
					this.initDataTixian()
				}
			},
			status_fun(type) {
				if (type == 2) {
					return '成功';
				} else if (type == 3) {
					return '失败'
				} else {
					return '待处理'
				}
			},
			initData() {
				recharge_record({
					page: this.page
				}).then(res => {
					if (res.data.status.errorCode == 0) {
						this.datas = [...this.datas, ...res.data.data.data.data]
					} else {
						uni.showToast({
							title: res.data.status.msg,
							icon: 'error',
							duration: 2000
						});
					}
				}).catch(err => {
					console.log(err)
				})
			},
			initDataTixian() {
				drawing_record({
					page: this.page
				}).then(res => {
					if (res.data.status.errorCode == 0) {
						this.datas = [...this.datas, ...res.data.data.data.data]
					} else {
						uni.showToast({
							title: res.data.status.msg,
							icon: 'error',
							duration: 2000
						});
					}
				}).catch(err => {
					console.log(err)
				})
			},
			goSwichPage(page) {
				uni.navigateTo({
					url: page
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.content {
		width: 100%;
		min-height: 100vh;
		background-color: #f1f1f7;
		color: #747474 !important;
	}

	.pages {
		padding-top: calc(calc(110rpx + 60rpx) + env(safe-area-inset-top));
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
	}


	.footer-bar {
		background-color: rgba(255, 255, 255, 0.95);
		padding: 0px 20rpx;
		position: fixed;
		bottom: 0px;
		left: 0px;
		right: 0px;
		z-index: 98;
		backdrop-filter: blur(20rpx);
		display: flex;
		text-align: center;
		transition: all 250ms ease;
		height: calc(120rpx + env(safe-area-inset-bottom));
		box-shadow: 0 -10rpx 10rpx 0 rgba(0, 0, 0, 0.04);
	}

	.footer-bar.footer-bar-detached {
		border-radius: 40rpx;
		left: 20rpx !important;
		right: 20rpx !important;
		bottom: 30rpx !important;
		box-shadow: 0 0px 30rpx 0 rgba(0, 0, 0, 0.1) !important;
		height: 120rpx !important;
	}

	.fbitem {
		color: #818181;
		position: relative;
		flex: 1 1 auto;
		padding-top: 24rpx;

		.image {
			height: 48rpx;
			margin-top: -4rpx;

			image {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.text {
			height: 48rpx;
			margin-top: -6rpx;
			font-size: 24rpx;
			opacity: 0.7;
			color: #818181;
		}
	}

	.nav_top {
		width: 100%;
		line-height: 80rpx;
		display: flex;
		font-size: 24rpx;
		margin-bottom: 10px;
	}

	.nav_top view {
		width: 50%;
		text-align: center;
		color: #0f1117;
	}

	.nav_top .on {
		color: #0f1117;
		background-image: url('../../static/img/blueBg.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		border-bottom: 5rpx solid #8bbcfe;
	}

	.card {
		width: 94%;
		margin: 0 auto;
		padding: 20px 0;
		border-radius: 20rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		word-wrap: break-word;
		background-color: #fff;
		box-shadow: rgba(0, 0, 0, .35) 0px 30px 60px -30px, rgba(0, 0, 0, .35) 0px -2px 6px 0px inset;
	}

	#nav_content_list {
		font-size: 24rpx;
	}

	.nav_content_list {
		display: flex;
		text-align: center;
		min-height: 60rpx;
	}

	#nav_content_list .title {
		font-weight: bold;
	}

	.nav_content_list view {}

	.nav_content_list .view1 {
		width: 30%;
	}

	.nav_content_list .view2 {
		width: 30%;
	}

	.nav_content_list .view3 {
		width: 40%;
	}

	.nav_content_list .view4 {
		width: 25%;
	}

	.tongguo {
		color: #4b89dc;
	}

	.weitongguo {
		color: red;
	}
</style>